﻿/**
 *	(C) 2014 Yuanjj
 *
 *	define user class
 *
 *	histroy
 * 		2014-07-01	Yuanjj		-	create
 */

#ifndef _USER_H_
#define _USER_H_

#include "typedef.h"
#include "define.h"

#define		NAME_LENGTH		64

#define		USER_NAME		(1<<0)
#define		USER_RIGHT		(1<<1)
#define		USER_ACTIVE		(1<<31)

/**
 *	user infomation struct
 */
typedef struct _user_info
{
    pem_s8_t		name[NAME_LENGTH];		// user name
    pem_s32_t		right;					// user right
    pem_bool_t		active;					// is it active
}user_info;

/**
 * 	user infomation manager class
 */
class cls_user
{
public:
    cls_user();
    ~cls_user();

protected:		// user infomation
    MUTEX_LOCK		m_lock;
    user_info		m_info;

public:
    /**
     *	get user name
     */
    pem_error_t	get_user_name( pem_s8_t* name, pem_s32_t size );

    /**
     *	get user right
     */
    pem_error_t	get_user_right( pem_s32_t* right );

    /**
     *	set user info into "m_info"
     */
    pem_error_t	set_user_info( user_info* info, pem_s32_t flag );

    /**
     *	load user info from db
     */
    pem_error_t load_user_info_from_db( pem_void_t* obj_bridge );

protected:
    /**
     *	get user name
     */
    pem_error_t	_get_user_name( pem_s8_t* name, pem_s32_t size );

    /**
     *	get user right
     */
    pem_error_t	_get_user_right( pem_s32_t* right );

    /**
     *	set user info into "m_info"
     */
    pem_error_t	_set_user_info( user_info* info, pem_s32_t flag );
};

#endif // _USER_H_
